package com.zhang.controller.member;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhang.common.util.result.R;
import com.zhang.common.util.result.RUtils;
import com.zhang.member.dto.UserPostsSearchDTO;
import com.zhang.member.entity.UserPosts;
import com.zhang.member.service.IUserPostsService;
import com.zhang.member.vo.UserPostListVO;
import com.zhang.member.vo.UserPostsInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("user/posts")
public class UserPostsController {
    @Autowired
    private IUserPostsService userPostsService;

    @PostMapping
    public R addUserPosts(@RequestBody UserPosts userPosts) {
        userPosts.setUserId(StpUtil.getLoginIdAsLong());
        userPostsService.createUserPosts(userPosts);
        return RUtils.successMsg("操作成功");
    }

    @PutMapping
    public R ModifyUserPosts(@RequestBody UserPosts userPosts) {
        userPostsService.ModifyUserPosts(userPosts);
        return RUtils.successMsg("操作成功");
    }

    @GetMapping("/info/{userPostsId}")
    public R getUserPostsById(@PathVariable String userPostsId) {
        UserPostsInfoVO userPostsInfoVO = userPostsService.getUserPostsById(userPostsId);
        return RUtils.successData(userPostsInfoVO);
    }

    @GetMapping("/list")
    public R getUserPosts(UserPostsSearchDTO dto) {
        List<UserPostListVO> vo = userPostsService.getUserPostsList(dto);
        return RUtils.successData(vo);
    }
}
